﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BySoft.Server.Business;
using BySoft.Web.Utility;
using BySoft.Web.Controls;
using BySoft.Server.Consts;
using BySoft.Server.Common;
using BySoft.Web.Site;

namespace BySoft.Web.Site.SysManage
{
    public partial class FormCheckList : AuthBasePage
    {
        private string m_strTbl = "FormCheckList";
        #region 变量定义
        int m_count = 0;

        #endregion

        #region 初始化及绑定控件
        private void BindData(int pageIndex)
        {
            DataTable dt = SysFormcheck.SelectList("");
     
            if (dt.Rows.Count != 0)
            {
                SetAddView(false); 
                grdResult.DataSource = dt;
                grdResult.DataBind(); 
            }
            else
            {
                SetAddView(true);
                UIHelper.BindEmptyGridView(grdResult, dt);
            }
            UIHelper.RunScript(this.Page, "iframeAutoFit();");
        }



        private void InitData()
        {
            BindData(0);
        }

        private void SetAddView(bool bView)
        {
            divAdd.Visible = bView;
        }
        #endregion

        #region 控件事件

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { 
                InitData();
            }
        } 

        /// <summary>
        ///   行事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grdResult_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string strCode = e.CommandArgument.ToString();
            //string strMention = "";
            switch (e.CommandName)
            {

                case "viewdata":
                    Response.Redirect(string.Format("FormCheckView.aspx?id={0}", HttpUtility.UrlEncode(strCode)));
                    break;
                case "edi":
                    Response.Redirect(string.Format("FormCheckEdit.aspx?id={0}", HttpUtility.UrlEncode(strCode)));
                    break;
                case "del":
                    SysFormaudit.Del(strCode);
                    BindData(0);
                    UIHelper.AlertMessage(this.Page, Message.DeleteSuccess);
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 行数据绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grdResult_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                #region 删除绑定
                ImageButton ibtn = (ImageButton)e.Row.FindControl("ibtnDel");
                Button btnDel = (Button)e.Row.FindControl("btnDel");
                if (ibtn != null)
                {
                    ibtn.OnClientClick = "ShowTopConfirm('提示信息','" + Message.ConfirmDelete +

        "','confirmCallback(\\'" + btnDel.ClientID + "\\')');return false;";
                }
                #endregion

            }
        }
        #endregion
    }
}

